
package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeowPurchaseOrders;
import com.ruoyi.system.service.IMeowPurchaseOrdersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

@Controller
@RequestMapping("/system/purchase-orders")
public class MeowPurchaseOrdersController extends BaseController {
    private final String prefix = "system/purchase-orders";

    @Autowired
    private IMeowPurchaseOrdersService purchaseOrdersService;

    @RequiresPermissions("system:purchase:view")
    @GetMapping
    public String ordersView() {
        return prefix + "/orders";
    }

    @RequiresPermissions("system:purchase:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeowPurchaseOrders orders) {
        startPage();
        List<MeowPurchaseOrders> list = purchaseOrdersService.selectMeowPurchaseOrdersList(orders);
        return getDataTable(list);
    }

    @RequiresPermissions("system:purchase:export")
    @Log(title = "采购订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeowPurchaseOrders orders) {
        List<MeowPurchaseOrders> list = purchaseOrdersService.selectMeowPurchaseOrdersList(orders);
        ExcelUtil<MeowPurchaseOrders> util = new ExcelUtil<>(MeowPurchaseOrders.class);
        return util.exportExcel(list, "采购订单数据");
    }

    @RequiresPermissions("system:purchase:add")
    @GetMapping("/add")
    public String addForm() {
        return prefix + "/add";
    }

    @RequiresPermissions("system:purchase:add")
    @Log(title = "采购订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSubmit(MeowPurchaseOrders orders) {
        return toAjax(purchaseOrdersService.insertMeowPurchaseOrders(orders));
    }

    @RequiresPermissions("system:purchase:edit")
    @GetMapping("/edit/{orderId}")
    public String editForm(@PathVariable String orderId, ModelMap mmap) {
        mmap.put("meowPurchaseOrders", purchaseOrdersService.selectMeowPurchaseOrdersByOrderId(orderId));
        return prefix + "/edit";
    }

    @RequiresPermissions("system:purchase:edit")
    @Log(title = "采购订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSubmit(MeowPurchaseOrders orders) {
        return toAjax(purchaseOrdersService.updateMeowPurchaseOrders(orders));
    }

    @RequiresPermissions("system:purchase:remove")
    @Log(title = "采购订单", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@RequestParam String ids) {
        return toAjax(purchaseOrdersService.deleteMeowPurchaseOrdersByOrderIds(ids));
    }
}
